<?php

require_once FRAMEWORK_DIR."/libraries/pfp/genericobject.php";  
require_once FRAMEWORK_DIR."/libraries/pfp/genericobjectcollection.php";

class GenericObjectCollectionTestCaseOutput extends UnitTestCase {
 var $_aTests = array();

function setUp(){

//print_r(debug_backtrace());
	  $this->_aTests = array();

for ($i=0;$i<10;$i++){
$oUser = NGenericObject::NI("#__user");
$oUser->setField("name","GenericObjectTest".$i);
$oUser->save();
//echo $oUser->getID()."<br/>";
$this->_aTests[$oUser->GetID()]=true;
//$this->_aTests[$i]=true;
unset($oUser);
}
//print_r($this->_aTests);


}


function testInstances(){
	//$oGOC1=NGenericObjectCollection::getInstance("#__user",'#__user','table');
}

function testGetAllUsers(){

$page_num=1;
$items_per_page=3;
$oGOC = new NGenericObjectCollection("#__user",'#__user','table');
$_sql = "SELECT id FROM #__user WHERE name like 'GenericObjectTest%' ORDER BY id";

$oGOC->SetPageSize($items_per_page);

$db=NFactory::getDBO();
$db->setQuery($_sql);
$oGOC->AddTuples($db->loadObjectList());

$this->assertEqual($oGOC->GetNumPages(),ceil($oGOC->GetItemCount() / $items_per_page ));

$this->assertEqual(count($this->_aTests),$oGOC->GetItemCount());


$page_num=1;

$oGOC->PopulateObjectArray($page_num);
$objArray = $oGOC->RetrievePopulatedObjects($page_num);

$this->assertEqual(count($objArray),$items_per_page);
$page_num=2;
$oGOC->PopulateObjectArray($page_num);
$objArray = $oGOC->RetrievePopulatedObjects($page_num);

$this->assertEqual(count($objArray),$items_per_page);

$page_num=3;
$oGOC->PopulateObjectArray($page_num);
$objArray = $oGOC->RetrievePopulatedObjects($page_num);

$this->assertEqual(count($objArray),$items_per_page);

$page_num=4;
$oGOC->PopulateObjectArray($page_num);
$objArray = $oGOC->RetrievePopulatedObjects($page_num);

$this->assertEqual(count($objArray),1);




//print_r($objArray);

	
	
}

function tearDown(){

foreach  ($this->_aTests as $id=>$value){
$oUser = NGenericObject::NI("#__user",$id);

$oUser->Destroy();
unset($oUser);
}
unset($this->_aTests);

}



}


?>